---
id: serial_outstation
title: Serial
sidebar_label: Serial
slug: /api/outstation/serial_outstation
---

import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';

Use the `Outstation::CreateSerialSessionFaultTolerant` method to create an outstation bound to a serial port. In addition to the common components, this method requires
the following serial port parameters:

* Path of the serial device (e.g., `COM3` on Windows or `/dev/ttyS3` on Linux)
* `SerialSettings` struct:
  * Baud rate
  * Data bits
  * Stop bits
  * Parity
  * Flow control
* Period of time for retrying the serial port if it cannot be opened or is fails because it is removed from the OS.

The method will then either open the port or fail if the port doesn't exist or is already in use. The returned `Outstation` class behaves identically to other transport types.

:::note
The `LinkErrorMode` is internally set to `Discard` for serial communication channels since serial ports do not provide data integrity.
:::

<Tabs
groupId="language"
defaultValue="Rust"
values={[
{label: 'Rust', value: 'Rust'},
{label: 'C', value: 'C'},
{label: 'C++', value: 'C++'},
{label: 'Java', value: 'Java'},
{label: 'C#', value: 'C#'},
]}>
<TabItem value="Rust">

```rust
{{#include ../dnp3/examples/outstation.rs:create_serial_server}}
```

</TabItem>
<TabItem value="C">

```c
{{#include ../ffi/bindings/c/outstation_example.c:create_serial_server}}
// check error
```

</TabItem>
<TabItem value="C++">

```cpp
{{#include ../ffi/bindings/c/outstation_example.cpp:create_serial_server}}
```

</TabItem>
<TabItem value="Java">

```java
{{#include ../ffi/bindings/java/examples/src/main/java/io/stepfunc/dnp3/examples/OutstationExample.java:create_serial_server}}
```

</TabItem>
<TabItem value="C#">

```csharp
{{#include ../ffi/bindings/dotnet/examples/outstation/Program.cs:create_serial_server}}
```

</TabItem>
</Tabs>

:::warning
There is also `Outstation::CreateSerialSession` method which opens the port on the calling thread and fails if it is not immediately available. The task spawned
by this thread will also shut down of the serial port is removed from the OS, e.g. if a USB to serial adapter is physically unplugged.

The fault-tolerant variant was added in the `1.1.0` release and is the preferred way of spawning a serial outstation. The non-fault tolerant version will be
removed in the next MAJOR release.
:::